/*
 * unittest1.c
 *
 *  Created on: Apr 27, 2014
 *      Author: chuaprar
 */

/*
 * Include the following lines in your makefile:
 *
 * unittest1: unittest1.c dominion.o rngs.o
 *      gcc -o unittest1 -g  unittest1.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <stdlib.h>

#define TESTFUNC "updateCoins()"

int main() {
    int i, j;
    int seed = 1000;
    int maxBonus = 5;
    int handCount;
    int bonus;
	int k[10] = {adventurer, embargo, village, minion, mine, cutpurse,
			sea_hag, tribute, smithy, council_room};
    struct gameState G;
    int maxHandCount = 5;
    int numPlayers = 2;
    int thisPlayer = 0;
    int copper_value = 1, silver_value = 2, gold_value = 3;

	printf("----------------- Testing: %s ----------------\n", TESTFUNC);

    for (handCount = 1; handCount <= maxHandCount; handCount++) {
		for (bonus = 0; bonus <= maxBonus; bonus++) {

			// test with all copper cards
			printf("Test: %d treasure card(s) and %d bonus.\n", handCount, bonus);
			initializeGame(numPlayers, k, seed, &G); // initialize a new game
			G.handCount[thisPlayer] = handCount;                 // set the number of cards on hand
			for (j=0; j<G.handCount[thisPlayer]; j++)
				G.hand[thisPlayer][j] = copper;

			updateCoins(thisPlayer, &G, bonus);
			printf("Copper coins: coins = %d, expected = %d\n", G.coins, handCount * copper_value + bonus);
			assert(G.coins == handCount * copper_value + bonus); // check if the number of coins is correct

			// test with all silver cards
			for (j=0; j<G.handCount[thisPlayer]; j++)
				G.hand[thisPlayer][j] = silver;
			updateCoins(thisPlayer, &G, bonus);
			printf("Silver coins: coins = %d, expected = %d\n", G.coins, handCount * silver_value + bonus);
			assert(G.coins == handCount * silver_value + bonus); // check if the number of coins is correct

			// test with all gold cards
			for (j=0; j<G.handCount[thisPlayer]; j++)
				G.hand[thisPlayer][j] = gold;
			updateCoins(thisPlayer, &G, bonus);
			printf("Gold coins: coins = %d, expected = %d\n", G.coins, handCount * gold_value + bonus);
			assert(G.coins == handCount * gold_value + bonus); // check if the number of coins is correct
		}
	}


    printf("\n >>>>> SUCCESS: Testing complete for %s <<<<<\n\n", TESTFUNC);

    return 0;
}

